#ifndef JOBMANAGEMENT_H
#define JOBMANAGEMENT_H
#include "global.h"
#include <QDialog>

namespace Ui {
class JobManagement;
}

class QPushButton;
class QGroupBox;
class QCheckBox;
class QListWidgetItem;

class JobManagement : public QDialog
{
    Q_OBJECT

public:
    explicit JobManagement(QSqlDatabase &database, QWidget *parent = 0);
    ~JobManagement();

    void clearInfoFrame(bool = false);
    void clearCitiesCheckBoxes(bool = false);
    void setEditMode(bool = true);
    void setAddMode(bool = true);
    bool isAddMode() const;

private:
    bool addNewRecordMode = false;
    Ui::JobManagement *ui;
    QPushButton *addRecordButton;
    QGroupBox *citiesGroupBox;
    QSqlQuery query;
    QMap<QString, int> companiesMap;
    QMap<QString, int> citiesMap;
    QMap<QString, int> listLabelToId;
    QMap<QString, QCheckBox *> citiesCheckBoxes;


    QMap<QString, int> mapGenerator(const QString &, const QString &);
    QStringList checkedCities();


private slots:

    void onListWidgetCurrentTextChanged(QString);
    void onInfoUpdated();
    void onAddButtonClicked();
    void onSaveButtonClicked();
    void onCancelButtonClicked();

};

inline void JobManagement::setAddMode(bool addNewRecordMode)
{
    this->addNewRecordMode = addNewRecordMode;
    if (addNewRecordMode)
        this->clearInfoFrame();
}

inline bool JobManagement::isAddMode() const
{
    return this->addNewRecordMode;
}

#endif // JOBMANAGEMENT_H
